package com.wx.tgp.jfinal.demo.service;

import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;
import com.sun.deploy.net.proxy.RemoveCommentReader;
import com.wx.tgp.jfinal.demo.entity.User;

/**
 * Created by Administrator on 2016/5/6.
 */
public class UserService {

    /**
     * 用户注册
     * @return
     */
    public boolean add(String username,String password){
        String SQL = "select userid from user where username=?";
        Integer result  = Db.queryFirst(SQL,username);
        if(result==null){
            Record studentUser = new Record().set("username",username).set("password",password);
            Db.save("user",studentUser);
            return true;
        }
        return false;
    }

    /**
     * 用户登陆
     * @return
     */
    public boolean login(String username,String password){
        String SQL = "select userid from user where username=? and password=?";
        Integer result = Db.queryFirst(SQL,username,password);
        if(result!=null){
            return true;
        }
        return false;
    }
}
